package src.java.SingleTon;

public class Singleton2 {
    //懒汉式：基本方式
    //缺点：加锁效率低
    //优点：线程安全，第一次调用才初始化，避免内存浪费

    private static Singleton2 instance;

    private Singleton2() {
    }

    public synchronized static Singleton2 getInstance() {
        if (instance == null) {
            instance = new Singleton2();
        }
        return instance;
    }
}
